<?php

namespace App\Model\Admin;

use Illuminate\Database\Eloquent\Model;

class Product extends Model
{
    protected $fillable = [
        'pro_name', 'pro_prices', 'pro_code','pro_img','pro_info','pro_description','spl_prices','cate_id','pro_stock','type_id','promote_price','promote_start_time','promote_end_time','is_promote','is_hot','is_new','is_best','is_floor'
    ];

    public function category()
    {
        return $this->belongsTo(\App\Model\Front\Category::class, 'cate_id', 'id');
    }

    public function wishlist()
    {
        return $this->hasMany('App\Model\Aboot\Wishlist', 'product_id', 'pro_code');
    }


    public function recommend()
    {
        return $this->hasMany('App\Model\Front\Recommend');
    }


    public function images()
    {
        return $this->hasMany('App\Model\Admin\ProductImage', 'product_id', 'pro_code');
    }
    
    public function getRouteKeyName()
    {
        return 'pro_code';
    }

    public function type()
    {
        return $this->hasOne('App\Model\Admin\ProductType', 'id', 'type_id');
    }

    public function attribute()
    {
        return $this->hasMany('App\Model\Admin\ProductAttr', 'id', 'type_id');
    }
    /**
     * [number 关联商品库存表]
     * @return [collection] [集合]
     */
    public function number()
    {
        return $this->hasMany('App\Model\Aboot\ProductNumber','product_id','id');
    }

     

}
